package com.anhuanjia.tools.eao.controller;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.anhuanjia.tools.eao.bean.EaoHelpMenu;
import com.efastsoft.framework.UIFacade;
import com.efastsoft.framework.annotation.Alias;
import com.efastsoft.framework.annotation.Priv;
import com.efastsoft.framework.annotation.Priv.LoginType;
import com.efastsoft.framework.data.DataRow;
import com.efastsoft.framework.data.DataTable;
import com.efastsoft.framework.data.Q;

/**
 * 帮助内容操作类
 * @author Administrator
 *
 */
@Alias(value = "help")
public class HelpUI extends UIFacade{
	
	/**
	 * 获取菜单
	 */
	@Priv(loginType = LoginType.Member)
	public void getMenus() {
		DataTable dt = new Q("select * from eao_help_menu where IsShow = '0' and Type = 1 order by Position").fetch();//type=1系统概述
		DataTable dt2 = new Q("select * from eao_help_menu where IsShow = '0' and Type = 2 order by Position").fetch();//type=2操作帮助
		List<EaoHelpMenu> hmList = new ArrayList<>();
		List<EaoHelpMenu> hmList2 = new ArrayList<>();
		for (DataRow dataRow : dt) {
			EaoHelpMenu hm = new EaoHelpMenu();
			hm.setValue(dataRow);
			hmList.add(hm);
		}
		for (DataRow dataRow : dt2) {
			EaoHelpMenu hm = new EaoHelpMenu();
			hm.setValue(dataRow);
			hmList2.add(hm);
		}
		
		List<EaoHelpMenu> hmTree = buildTree(hmList,0);
		List<EaoHelpMenu> hmTree2 = buildTree(hmList2,0);
		$S("hmTree1",JSON.toJSON(hmTree));
		$S("hmTree2",JSON.toJSON(hmTree2));
		
	}
	
	public static List<EaoHelpMenu> buildTree(List<EaoHelpMenu> list,int parentId){
		List<EaoHelpMenu> menus=new ArrayList<EaoHelpMenu>();
			for (EaoHelpMenu menu : list) {
			Integer menuId = menu.getId();
			int pid = menu.getParentId();
				if (parentId == pid) { 
				List<EaoHelpMenu> menuLists = buildTree(list, menuId);
				menu.setChildren(menuLists);
				menus.add(menu);
				}
			}
		return menus;
		}
}
